<?php
if (!defined('__BACKEND__'))
    die("you cannot directly access this page");
/*
 * by SONY K Wibisono
 * e-mail : sony@sonywibisono.com
 */
include ("class/AppUsers.php");
include ("class/AppRoles.php");
function preference_list(){
    global $db;
    $sql="select * from preferences";
    $result=$db->query($sql);
    echo "<div id=\"preferences\">
    <form action=\"?mod=panel&file=preference\" method=\"post\">
    <input type=\"hidden\" name=\"action\" value=\"save_pref\"/>
    <table>";
    while ($row=$db->fetch_array($result)){
        extract($row);
        echo "<tr><td>$pref_name</td>
        <td><input type=\"text\" name=\"pref['$pref_name']\" value=\"$pref_value\" /></td></tr>";
    }
    echo "</table></form></div>";
    
}
function module_list(){
    global $db,$is_admin;
     
    $sql="select * from app_modules order by title asc";
     
    $result=$db->query($sql);
    echo "<div id=\"menuHeader\"><div id=\"dockMenu\">";
    while ($row=$db->fetch_array($result)){
        extract($row);
        echo "<a href=\"?mod=$module_name\"> <img class=\"dockImage\" src=\"$url_icon\" 
        title=\"$description\"/></a>";
            
       
    }
    echo "</div></div><div stype=\"clear:both;\">&nbsp;
        <p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p></div>";
}
echo " ";
global $user_id,$is_admin,$login_status,$user_name,$action,$app_role;
if ($login_status){
    $user=new AppUsers();
    $user->open($user_name);
    $rolename=$user->getRole();
    //echo $app_role;
    $fullname=$user->full_name;
    $fullname=  ucwords($fullname);
    if (!isset($is_admin)){
        if ($user->app_role_id=='1'){
        $_SESSION['is_admin']=1;
        } else $_SESSION['is_admin']=0;
    }
    echo "<div style='padding:4px'><font size=\"+2\">Hi, <b>$fullname</b>  </font></div>";
    switch($action){
        case 'preference':
            preference_list();
            break;
        default:
            //echo "<div>Welcome to Online Helpdesk Management System <br> your role is <b>$rolename</b></div>"; 
            module_list();
            break;
    }
} else {
    echo "You are not Administrator, you cannot access this page";
}
echo " ";
?>